package com.lizhi.yun.sync.rsz.handler;/**
 * @program: hbsf_yun
 * @name RszTrainRecordSyncHandler
 * @description: 处方训练数据
 * @author: lizhi
 * @create: 2021-11-17 08:37
 */

import com.lizhi.common.yun.entity.RpcServicePOJO;
import com.lizhi.common.yun.enums.HeartBeartEnum;
import com.lizhi.utils.StringUtils;
import com.lizhi.utils.json.SamJsonUtil;
import com.lizhi.yun.db.rsz.dao.RszTrainRecordDao;
import com.lizhi.yun.db.rsz.entity.RszTrainRecordEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *@program: hbsf_yun
 *@name RszTrainRecordSyncHandler
 *@description: 处方训练数据
 *@author: lizhi
 *@create: 2021-11-17 08:37
 */
@Slf4j
@Service
public class RszTrainRecordSyncHandler {

    @Resource
    private RszTrainRecordDao rszTrainRecordDao;

    public String recv(String json){
        RpcServicePOJO rpcServicePOJO = new RpcServicePOJO();
        try {
            RszTrainRecordEntity rszTrainRecordEntity = SamJsonUtil.toObject(json, RszTrainRecordEntity.class);
            if (StringUtils.isEmpty(rszTrainRecordEntity)) {
                log.info("康复磨砂卓处方训练信息上传:{}", rszTrainRecordEntity);
                RszTrainRecordEntity trainRecordEntity = rszTrainRecordDao.selectById(rszTrainRecordEntity.recordId, rszTrainRecordEntity.hospitalId, rszTrainRecordEntity.hospitalSystemId);
                if (!StringUtils.isEmpty(trainRecordEntity)){
                    rszTrainRecordEntity.lid = trainRecordEntity.lid;
                    rszTrainRecordDao.updateByIdSelective(rszTrainRecordEntity);
                } else {
                    rszTrainRecordEntity.lid = StringUtils.newId();
                    rszTrainRecordDao.insertRecord(rszTrainRecordEntity);
                }
                rpcServicePOJO.setErrorCode(HeartBeartEnum.HEART_BEART_000000.getEnValue());
                rpcServicePOJO.setMessage(HeartBeartEnum.HEART_BEART_000000.getEnName());
            }
        } catch (Exception e){
            e.printStackTrace();
        }
        return SamJsonUtil.toJson(rpcServicePOJO);
    }
}
